/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 gdi_object_selector.h

	$Header: /heroes4/gdi_object_selector.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( GDI_OBJECT_SELECTOR_H_INCLUDED )
#define GDI_OBJECT_SELECTOR_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>

/////////////////////////////////////////////////////////////////////////////
template < typename t_gdi_handle >
class t_gdi_selector
{
public:
	// Constructor/Destructor
	t_gdi_selector( HDC hdc, t_gdi_handle gdi_handle );
	~t_gdi_selector() { ::SelectObject( m_hdc, m_old_gdi_handle ); }

private:
	// Data members
	HDC			m_hdc;
	HGDIOBJ		m_old_gdi_handle;
};

/////////////////////////////////////////////////////////////////////////////
template < typename t_gdi_handle >
inline t_gdi_selector< t_gdi_handle >::t_gdi_selector( HDC hdc, t_gdi_handle gdi_handle )
	:	m_hdc( hdc ),
		m_old_gdi_handle( ::SelectObject( hdc, static_cast< HGDIOBJ >( gdi_handle ) ) )
{
}

/////////////////////////////////////////////////////////////////////////////
typedef t_gdi_selector< HGDIOBJ > t_gdi_object_selector;
typedef t_gdi_selector< HBITMAP > t_gdi_bitmap_selector;
typedef t_gdi_selector< HBRUSH > t_gdi_brush_selector;
typedef t_gdi_selector< HFONT > t_gdi_font_selector;
typedef t_gdi_selector< HPEN > t_gdi_pen_selector;

#endif // !defined( GDI_OBJECT_SELECTOR_H_INCLUDED )
